package groovy.runtime.metaclass.com.webobjects.foundation;

import java.util.List;
import com.webobjects.foundation.NSArray;
import groovy.lang.*;

public class NSArrayMetaClass extends DelegatingMetaClass {

	public NSArrayMetaClass(MetaClass delegate) {
		super(delegate);
	}

	public Object invokeConstructor(final Object[] arguments) {
		Object[] newArguments = arguments;
		if (arguments==null)
			return super.invokeConstructor(arguments);
		if (arguments.length == 1 || arguments.length == 2) {
			Object arg1 = arguments[0];
			Object arg2 = true;
			if (arguments.length == 2 && arguments[1] instanceof Boolean)
				arg2 = arguments[1];

			if (arg1 instanceof List) {
				NSArray array = new NSArray((List)arg1, (Boolean)arg2);
				newArguments = new Object[] {array};
			}
		}
		return super.invokeConstructor(newArguments);
	}

}
